package com.EleRuler;

public class calculate {
	private double oriVertical;
	public double getOriVertical() {
		return oriVertical;
	}
	public void setOriVertical(double oriVertical) {
		this.oriVertical = oriVertical;
	}
	public calculate(){
		return;
	}
	public double calOri(double firstAccel,double secondAccel){
		firstAccel = firstAccel*Math.PI/180;
		secondAccel = secondAccel*Math.PI/180;
		double s = 0.5*(Math.cos(firstAccel)+Math.cos(secondAccel)+Math.sqrt(2));
		double S = Math.sqrt(s*(s-Math.cos(firstAccel))*(s-Math.cos(secondAccel))*(s-Math.sqrt(2)));
		double result = S/0.5;
		result = Math.sqrt(1-Math.pow(result, 2));
		if(result < 0)
			System.out.println("fuck\n");
		return oriVertical = Math.asin(result);
	}
	public double caldistance(double xAccel,double yAccel,myParameter my){
		double ori1 = this.calOri(xAccel, yAccel);
		double ori2 = this.calOri(my.getAccelZ(),my.getAccelY());
		double result;
		result = my.getHeight()*Math.tan(ori1)-my.getHeight()*Math.tan(ori2);
		return Math.abs(result);
	}
	public double calheight(double xAccel,double yAccel,myParameter my){
		double firstAccel = my.getAccelY()*Math.PI/180;
		double secondAccel = yAccel*Math.PI/180;
		double first = my.getDistance()/Math.tan(firstAccel);
		double second = my.getDistance()/Math.tan(secondAccel);
		double result ;
		result = Math.abs(first-second);
		return result;
		/*double ori1 = this.calOri(xAccel, yAccel);
		double ori2 = this.calOri(my.getAccelZ(),my.getAccelY());
		double first = Math.abs(my.getDistance()/Math.tan(ori1));
		double second = Math.abs(my.getDistance()/Math.tan(ori2));
		double result;
		if(my.getAccelY()*yAccel >= 0)
			result = Math.abs(first-second);
		else 8 
			result = Math.abs(first+second);
		return result;*/
	}
	public double callength(double xAccel,double yAccel,myParameter my,float r){
		double result ;
		result = r*my.getDistance()/175;
		result = result/Math.cos((yAccel+90)*Math.PI/180);
		return result;
	}
}
